package com.wbao.dianniu.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.KnowledgeData;
import com.wbao.dianniu.data.QaResponse;
import com.wbao.dianniu.data.QuestAnswerListData;
import com.wbao.dianniu.logical.Const;
import com.wbao.dianniu.ui.AmDetailActivity;
import com.wbao.dianniu.ui.HeadInfoActivity;
import com.wbao.dianniu.ui.KnowDetailActivity;
import com.wbao.dianniu.ui.QaDetailActivity;
import com.wbao.dianniu.ui.ReportActivity;
import com.wbao.dianniu.ui.SystemBarTintManager;
import com.wbao.dianniu.ui.TwoCommentKnowActivity;
import com.wbao.dianniu.ui.TwoCommentQaActivity;

import java.lang.reflect.Field;

/**
 * Created by yejianjun on 2018/6/10.
 */

public class ActivityUtils {


    /**
     * @param context
     * @param type    1：用户， 2：问答, 3：简历， 4：招聘， 5：活动 6：回复 7：知识分享
     * @param id
     */
    public static void intoReportActivity(Context context, int type, int id) {
        Intent jbIntent = new Intent();
        //类型3 举报求职简历
        jbIntent.putExtra(Const.INTENT_REPORT_TYPE, type);
        jbIntent.putExtra(Const.INTENT_REPORT_OBJECTID, id);
        jbIntent.setClass(context, ReportActivity.class);
        context.startActivity(jbIntent);
    }

    public static void intoAmDetailActivity(Context context, int questId) {
        Intent contentIntent = new Intent();
        contentIntent.putExtra(Const.BUNDLE_QUESTID, questId);
        contentIntent.setClass(context, AmDetailActivity.class);
        context.startActivity(contentIntent);
    }

    public static void intoKnowDetailActivity(Context context, int type, KnowledgeData knowledgeData) {
        Intent intent = new Intent();
        intent.putExtra(Const.INTENT_ID, knowledgeData.getId());
        intent.setClass(context, KnowDetailActivity.class);
        context.startActivity(intent);
    }


    public static void intoQaDetailActivity(Context context, QaResponse resp) {
        Intent contentIntent = new Intent();
        contentIntent.putExtra(Const.BUNDLE_QUESTID,resp.id);
        contentIntent.setClass(context, QaDetailActivity.class);
        context.startActivity(contentIntent);
    }

    /**
     * @param mContext
     * @param questId
     * @param pid
     * @param type     1 2 跳转到二级回复 3： 跳转到干货回复
     */
    public static void intoTwoCommentActivity(Context mContext, int questId, int pid, int type, QuestAnswerListData data) {
        Intent intent = new Intent();
        intent.putExtra(Const.BUNDLE_QUESTID, questId);
        intent.putExtra(Const.INTENT_ID, pid);
        intent.putExtra(Const.BUNDLE_ADVERT, type);

        // 如果anonymous初始值为空 给0处理
        if (null == data.anonymous) {
            data.anonymous = 0;
        }

        // 带一级回复的内容到二级回复列表 headpic  name sex partner label addV conent answerImgs priceCounts comments
        Bundle bundle = new Bundle();
        bundle.putInt(Const.BUNDLE_ID, data.id);
        bundle.putString(Const.BUNDLE_HEADPIC, data.userInfo.headPic);
        bundle.putInt(Const.BUNDLE_ACCOUNTID, data.userInfo.accountId);
        bundle.putString(Const.BUNDLE_REALNAME, data.userInfo.realName);
        bundle.putString(Const.BUNDLE_LABEL, data.userInfo.label);
        bundle.putInt(Const.INTENT_SEX, data.userInfo.sex);
        bundle.putInt(Const.BUNDLE_PARTNER, data.userInfo.partner);
        bundle.putBoolean(Const.BUNDLE_ISINDUSTRYAUTHORITY, data.userInfo.isIndustryAuthority);
        bundle.putString(Const.BUNDLE_CONTENT, data.content);
        bundle.putString(Const.BUNDLE_QUESTIMGS, data.answerImgs);
        bundle.putString(Const.BUNDLE_NOTICEJSON, data.noticeJson);
        bundle.putInt(Const.BUNDLE_GOODCOUNT, data.goodCount);
        bundle.putInt(Const.BUNDLE_ISGOOD, data.isGood);
        bundle.putInt(Const.BUNDLE_ANSWERCOUNT, data.childrensCount);
        bundle.putInt(Const.BUNDLE_ANONYMOUS, data.anonymous);
        intent.putExtra(Const.BUNDLE_DATA, bundle);

        if (type == AnswerListType.TYPE_KNOW) {
            intent.setClass(mContext, TwoCommentKnowActivity.class);
        } else {
            intent.setClass(mContext, TwoCommentQaActivity.class);
        }
        mContext.startActivity(intent);
    }

    public static void intoHeadInfoActivity(Integer accountId, Context context) {
        Intent headIntent = new Intent();
        headIntent.putExtra(HeadInfoActivity.INTENT_FRIENDID, accountId);
        headIntent.setClass(context, HeadInfoActivity.class);
        context.startActivity(headIntent);
    }


    /**
     * 设置沉浸式状态栏颜色
     *
     * @param activity
     */
    public static void setStatusBarColor(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // 系统版本大于19
            /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                try {
                    Class decorViewClazz = Class.forName("com.android.internal.policy.DecorView");
                    Field field = decorViewClazz.getDeclaredField("mSemiTransparentStatusBarColor");
                    field.setAccessible(true);
                    field.setInt(activity.getWindow().getDecorView(), Color.TRANSPARENT);  //改为透明
                } catch (Exception e) {
                }
            }*/
            Utils.setTranslucentStatus(activity, true);
            SystemBarTintManager tintManager = new SystemBarTintManager(activity);
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.title_bg);// 通知栏所需颜色
        }
    }

}
